<?php
App::uses('AppHelper', 'View/Helper');
class MenuHelper extends AppHelper {
	public $helpers = array('Html');
	
	public function breadcrumb(){
		$pathMenu = $this->_View->get('pathMenu');
		$language = Configure::read('Config.language');
		
		if(is_array($pathMenu)){
			if(count($pathMenu) == 1 && isset($pathMenu[0]['Menus']['slug']) && $pathMenu[0]['Menus']['slug'] == '/') return;
			foreach ($pathMenu as $key => $m) {
				if($m['Menus']['slug'] != '/')
				$this->Html->addCrumb($m['Menus']['name'], '/'.$m['Menus']['slug'],array('title'=>$m['Menus']['name']));
			}			
		}
		$pathSubmenu = $this->_View->get('pathSubmenu');
		if(is_array($pathSubmenu)){
			foreach ($pathSubmenu as $key => $m) {
				$this->Html->addCrumb($m['Submenu']['name'], '/'.$m['Submenu']['slug'],array('title'=>$m['Submenu']['name']));
			}
		}	
		$patchArticle = $this->_View->get('patchArticle');
		$article_count = $this->_View->get('article_count');
		if(is_array($patchArticle) && !empty($patchArticle) && $article_count > 1){
			$this->Html->addCrumb($patchArticle['name'], '/'.'/a/'.$patchArticle['slug'],array('title'=>$patchArticle['name']));
		}		
		
		return $this->Html->getCrumbs(false, Configure::read('cfg.homepage_name'),array('title'=>Configure::read('cfg.homepage_name')));		
	}
	
	public function homepage_thumbs(){
		$menus = $this->_View->get('mainMenu');
		$t = array();
		foreach ($menus as $key => $menu) {
			if(is_null($menu['Menus']['parent_id'])){
				$t[$menu['Menus']['id']]['name'] = $menu['Menus']['name'];
				$t[$menu['Menus']['id']]['slug'] = $menu['Menus']['slug'];
				$t[$menu['Menus']['id']]['title'] = $menu['Menus']['title'];
				$t[$menu['Menus']['id']]['image'] = (isset($menu['Upload']['name'])) ? $menu['Upload']['name'] : null ;
			}
		}
		echo $this->_View->element('Menu.homepageThumbs',array('menu_thumbs'=> $t));
	}	

}